package vn.bang.xiangqi.utility;

import java.util.Map;

import vn.bang.xiangqi.components.INode;
import vn.bang.xiangqi.components.NodeKind;
import vn.bang.xiangqi.infrastructure.Position;

public class BoardUtil
{
    static public int MAX_LOG_RECORDS = 200;
    static public int NUMBER_OF_PLAYERS = 2;
    static public int COLUMN_INDEX_MAX = 9;
    static public int ROW_INDEX_MAX = 10;

    static public INode GetNodeInList(NodeKind nodeKind, int order, Map<Integer, INode> playerNodes)
    {
        int key = nodeKind.getIndex() + order;
        return playerNodes.get(key);
    }

    static public boolean IsInBoard(Position position)
    {
        return ColumnIndexInBoard(position.getColumnIndex()) && RowIndexInBoard(position.getRowIndex());
    }

    static public boolean ColumnIndexInBoard(int columnIndex)
    {
        return validateIndex(COLUMN_INDEX_MAX, columnIndex);
    }

    static public boolean RowIndexInBoard(int rowIndex)
    {
        return validateIndex(ROW_INDEX_MAX, rowIndex);
    }

    static private boolean validateIndex(int maxNumber, int number)
    {
        if (number < 1)
        {
            return false;
        }

        if (maxNumber < number)
        {
            return false;
        }

        return true;
    }

}
